import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:verse_systems/commom/models/product_model.dart';
import 'package:verse_systems/res/colors.dart';

class ProductItem extends StatelessWidget {
  final ProductModel? model;
  final VoidCallback? onPressed;
  const ProductItem({super.key, this.model, required this.onPressed});

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 125.w,
      decoration: BoxDecoration(
        borderRadius: BorderRadius.all(Radius.circular(8.w)),
        color: Colours.app_main_color,
      ),
      margin: EdgeInsets.symmetric(horizontal: 15.w, vertical: 6.w),
      padding: EdgeInsets.symmetric(horizontal: 15.w, vertical: 15.w),
      child: Column(
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Row(
                children: [
                  Container(
                    width: 38.w,
                    height: 38.w,
                    decoration: BoxDecoration(
                        color: Colours.app_icon_bg_color,
                        image: DecorationImage(
                            fit: BoxFit.fill,
                            onError: (Object error, StackTrace? stackTrace) {
                              debugPrint("onError---${error.toString()}");
                            },
                            image: NetworkImage(model?.icon ?? "")),
                        borderRadius: BorderRadius.circular(10.w)),
                  ),
                  Container(
                    margin: EdgeInsets.only(left: 17.w),
                    child: Column(
                      children: [
                        Text(
                          model?.name ?? "",
                          style: TextStyle(
                            color: Colours.app_black_text_color,
                            fontSize: 14.sp,
                          ),
                        ),
                        Text(
                          "${model?.download ?? "0"}${"downloaded".tr}",
                          style: TextStyle(
                            color: Colours.app_black_text_color,
                            fontSize: 10.sp,
                          ),
                        ),
                      ],
                    ),
                  )
                ],
              ),
              InkWell(
                onTap: onPressed,
                child: Container(
                  width: 100.w,
                  height: 34.w,
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(17.w),
                    gradient: const LinearGradient(colors: [
                      Color(0xFFFC5B2C),
                      Color(0xFFFF3C23),
                    ]),
                  ),
                  alignment: Alignment.center,
                  child: Text(
                    "go_borrow_money".tr,
                    style: TextStyle(
                      color: Colours.app_main_color,
                      fontSize: 14.sp,
                    ),
                  ),
                ),
              )
            ],
          ),
          SizedBox(height: 14.5.w),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: _tagList(),
          )
        ],
      ),
    );
  }

  List<Widget> _tagList() {
    final List<Widget> listWidget = [
      {"title": "amount".tr, "name": model?.quoa.toString()},
      {"title": "borrowing_days".tr, "name": model?.days.toString()},
      {"title": "annual_rate".tr, "name": model?.rate.toString()}
    ].map((val) {
      return Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          Text(
            val["title"].toString(),
            style: TextStyle(
              color: Colours.app_line_color,
              fontSize: 11.sp,
            ),
          ),
          SizedBox(height: 5.w),
          Text(
            val["name"].toString(),
            style: TextStyle(
              color: Colours.mine_tag_text_color,
              fontSize: 15.sp,
            ),
          )
        ],
      );
    }).toList();
    return listWidget;
  }
}
